package com.our.shop.system.common;

import java.util.Map;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.our.shop.system.interceptor.LoginInterceptor;

public class AdminSessionListener implements HttpSessionAttributeListener {
	private static final Logger logger = LoggerFactory.getLogger(AdminSessionListener.class);

	public void attributeAdded(HttpSessionBindingEvent event) {
		String sessionAttributeName = event.getName();
		if ("loginUser".equals(sessionAttributeName)) {
			HttpSession session = event.getSession();
			String id = session.getId() + session.getCreationTime();

			/*SysUser systemUser = (SysUser) event.getValue();
			synchronized (this) {
				Static.ADMIN_LOGIN_USER_SUM += 1;
				Static.ADMIN_LOGIN_USERS.put(id, systemUser);

				log();
			}*/
		}
	}

	public void attributeRemoved(HttpSessionBindingEvent event) {
		String sessionAttributeName = event.getName();
		if ("loginUser".equals(sessionAttributeName)) {
			HttpSession session = event.getSession();
			String id = session.getId() + session.getCreationTime();
/*
			synchronized (this) {
				Static.ADMIN_LOGIN_USER_SUM -= 1;
				Static.ADMIN_LOGIN_USERS.remove(id);

				log();
			}*/
		}
	}

	public void attributeReplaced(HttpSessionBindingEvent event) {
		String sessionAttributeName = event.getName();
		if ("loginUser".equals(sessionAttributeName)) {
			HttpSession session = event.getSession();
			String id = session.getId() + session.getCreationTime();

			/*SysUser systemUser = (SysUser) event.getValue();
			synchronized (this) {
				Static.ADMIN_LOGIN_USERS.put(id, systemUser);

				log();
			}*/
		}
	}
}